//控制单位打迫击炮
params ["_unit"];
if(side _unit == east) exitWith{};//红军不打
private _veh = vehicle _unit;
if(_veh == _unit) exitWith{};

private ["_player", "_count"];
_count = 0;


while{(!isNull _unit) && {alive _unit} && {!isNull _veh} && {alive _veh}}do
{
	sleep 16;
	if((isNull _unit) || (!alive _unit)) exitWith {};
	
	if(simulationEnabled _unit) then{
	
		_player = [_unit, 1500, 50] call fn_getPlayerAttack;
		
		if !(isNull _player) then
		{
			sleep 5;
			//攻击
			private _ammoArray = getArtilleryAmmo [_veh];
			if (isNil "_ammoArray") exitWith {};

			private _randomAmmoArray = selectRandom _ammoArray;
			if (isNil "_randomAmmoArray") exitWith {};
			
			private _player_pos = (_unit targetKnowledge _player) select 6;//上次看到的位置
			private _dis = _player_pos distance2d _unit;
			if(_dis > 800)then
			{//固定100米散布
				//3发散射
				_unit doArtilleryFire [_player_pos getPos [random 100, random 360], _randomAmmoArray, 1];
				sleep 1;
				_unit doArtilleryFire [_player_pos getPos [random 100, random 360], _randomAmmoArray, 1];
				sleep 1;
				_unit doArtilleryFire [_player_pos getPos [random 100, random 360], _randomAmmoArray, 1];
				
			}else{
			//近距离
				if((_player distanceSqr _player_pos) > 625) then
				{//脱离了视野
					//systemChat "脱离了视野";
					_unit forgetTarget _player;
				}
				else
				{
					private _spread = 30;//每次射击降低5米散布，每100米增加2米散布
					_spread = _spread + (_player_pos distance _unit) * 0.02;
					_spread = _spread - _count * 5;
					if(_spread < 3) then{
						_spread = 3;
					};
					//3发连射
					_unit doArtilleryFire [_player_pos getPos [_spread + random _spread, random 360], _randomAmmoArray, 3];
					
					_count = _count + 1;
				};
			};
		}
		else
		{
			_count = 0;
		};
	};
};
						